package com.ruoyi.project.manage.item.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.manage.item.domain.StageItem;
import com.ruoyi.project.manage.item.service.IStageItemService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 阶段事项Controller
 * 
 * @author fangkun
 * @date 2022-04-02
 */
@Controller
@RequestMapping("/manage/item")
public class StageItemController extends BaseController
{
    private String prefix = "manage/item";

    @Autowired
    private IStageItemService stageItemService;

    @RequiresPermissions("manage:item:view")
    @GetMapping()
    public String item()
    {
        return prefix + "/item";
    }

    /**
     * 查询阶段事项列表
     */
    @RequiresPermissions("manage:item:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StageItem stageItem)
    {
        startPage();
        List<StageItem> list = stageItemService.selectStageItemList(stageItem);
        return getDataTable(list);
    }

    /**
     * 导出阶段事项列表
     */
    @RequiresPermissions("manage:item:export")
    @Log(title = "阶段事项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StageItem stageItem)
    {
        List<StageItem> list = stageItemService.selectStageItemList(stageItem);
        ExcelUtil<StageItem> util = new ExcelUtil<StageItem>(StageItem.class);
        return util.exportExcel(list, "阶段事项数据");
    }

    /**
     * 新增阶段事项
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存阶段事项
     */
    @RequiresPermissions("manage:item:add")
    @Log(title = "阶段事项", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StageItem stageItem)
    {
        return toAjax(stageItemService.insertStageItem(stageItem));
    }

    /**
     * 修改阶段事项
     */
    @RequiresPermissions("manage:item:edit")
    @GetMapping("/edit/{stageItemId}")
    public String edit(@PathVariable("stageItemId") Long stageItemId, ModelMap mmap)
    {
        StageItem stageItem = stageItemService.selectStageItemByStageItemId(stageItemId);
        mmap.put("stageItem", stageItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存阶段事项
     */
    @RequiresPermissions("manage:item:edit")
    @Log(title = "阶段事项", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StageItem stageItem)
    {
        return toAjax(stageItemService.updateStageItem(stageItem));
    }

    /**
     * 删除阶段事项
     */
    @RequiresPermissions("manage:item:remove")
    @Log(title = "阶段事项", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stageItemService.deleteStageItemByStageItemIds(ids));
    }
}
